#pragma once
#include "joui.h"
#include "config.h"
#include "element/control_api.h"
namespace JOUI
{
	EXINTERFACE("A1DBE474-01C9-4196-A38D-F46AB0EEECC4") IUIButton: public IUIControl
	{
		EXMETHOD void CALLAPI SetStyle(info_button_type type = fill, info_button_style style = normal) PURE;
		EXMETHOD void CALLAPI SetCrText(INT normal, INT hover, INT down) PURE;
		EXMETHOD void CALLAPI SetCrBorder(INT normal, INT hover, INT down) PURE;
		EXMETHOD void CALLAPI SetCrBkg(INT normal, INT hover, INT down) PURE;
		EXMETHOD void CALLAPI SetImgBkg(UIimage normal, UIimage hover, UIimage down) PURE;
		EXMETHOD void CALLAPI SetRadius(FLOAT fRadius) PURE;
		EXMETHOD void CALLAPI SetIcon(UIimage fIcon, INT fIconPosition = 0) PURE;
	};



	class ExButton : public ExObjectImpl<IUIButton>, UIButton
	{
	public:
		EX_BEGIN_INTERFACE_MAP();
		EX_INTERFACE_ENTRY(IUnknown);
		EX_INTERFACE_ENTRY(IExLayout);
		EX_INTERFACE_ENTRY(IUIControl);
		EX_INTERFACE_ENTRY(IUIButton);
		EX_END_INTERFACE_MAP();

		EXMETHOD BOOL CALLAPI Layout_Init(INT nType);
		EXMETHOD BOOL CALLAPI Layout_Update();
		EXMETHOD INT CALLAPI Layout_GetType();
		EXMETHOD BOOL CALLAPI Layout_SetChildProp(LPVOID parent, INT dwPropID, size_t pvValue);
		EXMETHOD BOOL CALLAPI Layout_SetProp(INT dwPropID, size_t pvValue);
		EXMETHOD BOOL CALLAPI Layout_Absolute_Lock(LPVOID hObjChild, INT tLeft, INT tTop, INT tRight, INT tBottom, INT tWidth, INT tHeight);
		EXMETHOD BOOL CALLAPI Layout_Absolute_Setedge(LPVOID hObjChild, INT dwEdge, INT dwType, size_t nValue);
		EXMETHOD BOOL CALLAPI Layout_AddChild(LPVOID parent);
		EXMETHOD BOOL CALLAPI Layout_AddChildren(BOOL fDesc, LPCWSTR dwObjClass, INT* nCount);
		EXMETHOD BOOL CALLAPI Layout_DeleteChild(LPVOID parent);
		EXMETHOD BOOL CALLAPI Layout_DeleteChildren(LPCWSTR dwObjClass = NULL);

		EXMETHOD void CALLAPI InitSubControl(LPVOID hParent, INT x, INT y, INT width, INT height, LPCWSTR lpClsname, LPCWSTR lpszName, INT dwStyle, INT dwStyleEx, INT nID,
			INT dwTextFormat, LPARAM lParam = 0, ClsPROC pfnClsProc = 0);
		EXMETHOD LPVOID CALLAPI GetHandle();
		EXMETHOD void CALLAPI Move(INT x, INT y, INT width = CW_USEDEFAULT, INT height = CW_USEDEFAULT, BOOL bRepaint = false);
		EXMETHOD void CALLAPI SetPos(INT x, INT y, INT width, INT height, HWND hObjInsertAfter = HWND_TOP, INT flags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
		EXMETHOD void CALLAPI Redraw(RECT* lprcRedraw = NULL);
		EXMETHOD BOOL CALLAPI BeginPaint(ps_context& lpPS);
		EXMETHOD void CALLAPI EndPaint();
		EXMETHOD void CALLAPI Show(BOOL fShow);
		EXMETHOD BOOL CALLAPI IsVisible();
		EXMETHOD void CALLAPI Enable(BOOL fEnable);
		EXMETHOD BOOL CALLAPI IsEnable();
		EXMETHOD BOOL CALLAPI SetFocus();
		EXMETHOD LPVOID CALLAPI GetFocus();
		EXMETHOD void CALLAPI KillFocus();
		EXMETHOD BOOL CALLAPI SetText(LPCWSTR lpString);
		EXMETHOD void CALLAPI GetText(LPCWSTR& lpString);
		EXMETHOD INT CALLAPI SetTextFormat(DWORD dwTextFormat, BOOL bRedraw = false);
		EXMETHOD void CALLAPI SetPadding(INT left, INT top, INT right = CW_USEDEFAULT, INT bottom = CW_USEDEFAULT, BOOL fRedraw = false);
		EXMETHOD void CALLAPI SetTipsText(LPCWSTR lpString, INT crBlack, INT crText);
		EXMETHOD void CALLAPI TooltipsPop(LPCWSTR lpTitle, LPCWSTR lpText, INT crBlack, INT crText, INT x = -1, INT y = -1, INT dwTime = -1, INT nIcon = TTI_NONE, BOOL fShow = false);
		EXMETHOD size_t CALLAPI DispatchNotify(INT nCode, WPARAM wParam, LPARAM lParam);
		EXMETHOD size_t CALLAPI SendMsg(INT uMsg, WPARAM wParam = 0, LPARAM lParam = 0);
		EXMETHOD BOOL CALLAPI SetEvent(INT nEvent, EventHandlerPROC pfnCallback);
		EXMETHOD void CALLAPI SetMsgProc(ObjMsgPROC pfnCallback);
		EXMETHOD void CALLAPI SetState(DWORD dwState = state_normal, BOOL fRemove = false, RECT* lprcRedraw = 0, BOOL fRedraw = false);
		EXMETHOD INT CALLAPI GetState();
		EXMETHOD BOOL CALLAPI GetRect(RECT& lpRect, INT nType = grt_default, BOOL fScale = false);
		EXMETHOD LPVOID CALLAPI GetNode(INT nCmd);
		EXMETHOD void CALLAPI GetColor(INT nIndex, INT& rel);
		EXMETHOD BOOL CALLAPI SetColor(INT nIndex, INT dwColor, BOOL fRedraw = false);
		EXMETHOD LPVOID CALLAPI GetFromUIWnd();
		EXMETHOD HWND CALLAPI GethWnd();
		EXMETHOD void CALLAPI SetParent(LPVOID hParent);
		EXMETHOD LPVOID CALLAPI GetParent(BOOL tParent = false);
		EXMETHOD LPVOID CALLAPI GetParentUIWnd();
		EXMETHOD void CALLAPI GetlClassName(LPCWSTR& lpClassName);
		EXMETHOD void CALLAPI SetRadius(FLOAT topleft, FLOAT topright, FLOAT bottomright, FLOAT bottomleft, BOOL fUpdate = false);
		EXMETHOD BOOL CALLAPI SetFontFromFamily(LPCWSTR lpszFontfamily, INT dwFontsize = -1, INT dwFontstyle = FontStyle::Normal, BOOL fRedraw = false);
		EXMETHOD BOOL CALLAPI SetFontLogFont(LOGFONTW* Fontinfo, BOOL fRedraw = false);
		EXMETHOD UIfont CALLAPI GetFont();
		EXMETHOD BOOL CALLAPI SetBackgImageFromMemory(LPVOID lpImage, size_t dwImageLen, INT x = 0, INT y = 0, DWORD dwRepeat = bir_default, RECT* lpGrid = 0, INT dwFlags = bif_default, DWORD dwAlpha = 255);
		EXMETHOD BOOL CALLAPI SetBackgImageFromHandle(UIimage* hImage, BOOL fReset = false, INT x = 0, INT y = 0, DWORD dwRepeat = bir_default, RECT* lpGrid = 0, INT dwFlags = bif_default, DWORD dwAlpha = 255);
		EXMETHOD BOOL CALLAPI SetBackgImageFromFile(LPCWSTR lpImagefile, INT x = 0, INT y = 0, DWORD dwRepeat = bir_default, RECT* lpGrid = 0, INT dwFlags = bif_default, DWORD dwAlpha = 255);
		EXMETHOD void CALLAPI SetBackgInfo(INT x = 0, INT y = 0, RECT* lpGrid = 0, INT dwFlags = bif_default, DWORD dwAlpha = 255);
		EXMETHOD BOOL CALLAPI SetBackgPlay(BOOL fPlayFrames, BOOL fResetFrame = false);
		EXMETHOD void CALLAPI SetBlur(FLOAT fDeviation, BOOL fmodesoft = false, BOOL bRedraw = false);
		EXMETHOD BOOL CALLAPI SetTimer(UINT uTimeout);
		EXMETHOD BOOL CALLAPI KillTimer();
		EXMETHOD void CALLAPI SetAlpha(INT fAlpha);
		EXMETHOD void CALLAPI SetID(INT nID);
		EXMETHOD INT CALLAPI GetID();
		EXMETHOD LPARAM CALLAPI GetlParam();
		EXMETHOD void CALLAPI SetlParam(LPARAM dwlParam);
		EXMETHOD INT CALLAPI Style(INT dwStyle = -1);
		EXMETHOD INT CALLAPI StyleEx(INT dwStyleEx = -1);
		EXMETHOD BOOL CALLAPI GetScrollInfo(BOOL bHScroll, INT& lpnMin, INT& lpnMax, INT& lpnPos, INT& lpnTrackPos);
		EXMETHOD INT CALLAPI SetScrollInfo(BOOL bHScroll, INT Mask, INT nMin, INT nMax, INT nPage, INT nPos, BOOL bRedraw = false);
		EXMETHOD INT CALLAPI GetScrollPos(BOOL bHScroll);
		EXMETHOD INT CALLAPI SetScrollPos(BOOL bHScroll, INT nPos, BOOL bRedraw = false);
		EXMETHOD INT CALLAPI SetScrollRange(BOOL bHScroll, INT nMin, INT nMax, BOOL bRedraw = false);
		EXMETHOD BOOL CALLAPI GetScrollRange(BOOL bHScroll, INT& lpnMinPos, INT& lpnMaxPos);
		EXMETHOD INT CALLAPI GetScrollTrackPos(BOOL bHScroll);
		EXMETHOD void CALLAPI SetScrollShow(BOOL bHScroll, BOOL fShow = false);
		EXMETHOD void CALLAPI SetScrollEnable(INT wSB = SB_BOTH, INT wArrows = ESB_DISABLE_BOTH);
		EXMETHOD void CALLAPI SetScrollColor(INT color_normal, INT color_hover, INT color_down, INT color_btn_up, INT color_btn_down, BOOL bRedraw = false);
		EXMETHOD void CALLAPI SetScrollRadius(BOOL bRadius);
		EXMETHOD INT CALLAPI PostScrollMsg(INT uMsg, WPARAM wParam, LPARAM lParam, INT nLine = 0);
		EXMETHOD void CALLAPI SetCursor(HCURSOR fCursor);
		EXMETHOD HRESULT CALLAPI ToImage(UIimage& dstImg, BOOL cdraw = false);
		EXMETHOD HRESULT CALLAPI CheckDropFormat(LPVOID pDataObject, DWORD dwFormat = 0);
		EXMETHOD INT CALLAPI CheckDropString(LPVOID pDataObject, LPWSTR lpwzBuffer, INT cchMaxLength);
		EXMETHOD UINT CALLAPI CheckDropFileNumber(WPARAM wParam);
		EXMETHOD UINT CALLAPI CheckDragQueryFile(WPARAM wParam, UINT iFile, LPWSTR lpszFile, UINT cch);
		EXMETHOD BOOL CALLAPI Lock(INT Left, INT Top, INT Right, INT Bottom, INT Width = -1, INT Height = -1);
		EXMETHOD LPVOID CALLAPI FindUIView(LPCWSTR lpName);
	public:
		ExButton(UIBase* hParent, INT x = 0, INT y = 0, INT width = 0, INT height = 0, LPCWSTR lpszName = NULL, INT dwStyle = 0, INT dwStyleEx = eos_ex_focusable, INT nID = 0, INT dwTextFormat = -1)
			:UIButton(hParent, x, y, width, height, lpszName, dwStyle, dwStyleEx, nID, dwTextFormat) {}
		virtual ~ExButton();

		EXMETHOD void CALLAPI SetStyle(info_button_type type = fill, info_button_style style = normal);
		EXMETHOD void CALLAPI SetCrText(INT normal, INT hover, INT down);
		EXMETHOD void CALLAPI SetCrBorder(INT normal, INT hover, INT down);
		EXMETHOD void CALLAPI SetCrBkg(INT normal, INT hover, INT down);
		EXMETHOD void CALLAPI SetImgBkg(UIimage normal, UIimage hover, UIimage down);
		EXMETHOD void CALLAPI SetRadius(FLOAT fRadius);
		EXMETHOD void CALLAPI SetIcon(UIimage fIcon, INT fIconPosition = 0);
	};


	BOOL IUIButtonCreate(IUIButton** r_IControl, LPVOID hParent, INT x = 0, INT y = 0, INT width = 0, INT height = 0, LPCWSTR lpszName = NULL, INT dwStyle = 0, INT dwStyleEx = eos_ex_focusable, INT nID = 0, INT dwTextFormat = -1);
}